<?php
/**
 * Created by 上海风车教育科技有限公司.
 * User: 刘红伟
 * Date: 15-12-10
 * Email: 454303753@qq.com
 * File:wx_jsapi_pay.php
 */
class wx_jsapi_pay{
    private  $prepay_id;
    private  $time;
    public function __construct($prepay_id){
        $this->prepay_id=$prepay_id;
        $this->time=time();
    }

    private function set_nonce_str(){
        return md5($this->time.'wxcf2296ea434d481b'.'1289649501');
    }
    private function getPaySign(){
        $str="appId=".Yii::app()->params['APPID']."&nonceStr=".$this->set_nonce_str()."&package=prepay_id=".$this->prepay_id."&signType=MD5&timeStamp=".$this->time."&key=".Yii::app()->params['weixin_key'];
        return strtoupper(md5($str));
    }


    public function get_pay_config(){
        return array(
            'appId'=>Yii::app()->params['APPID'],
            'nonceStr'=>$this->set_nonce_str(),
            'package'=>'prepay_id='.$this->prepay_id,
            'signType'=>'MD5',
            'timeStamp'=>"$this->time",
            'paySign'=>$this->getPaySign()
        );

    }
}